<?
layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div id="page-wrapper" style="margin-left: 0px;">
       
      <!--BEGIN CONTENT-->
      <div style="height:515px; overflow:auto" >
      
      <div class="row mbl" style="margin-top: 10px;">
           <div class="col-lg-6">
               <div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                     <option value="-1">筛选项&nbsp;<span class="caret"></span></option>
		                    <option value="nameZh">中文名称</option>
		                    <option value="nameEn">英文名称</option>
                    	</select>
                   	</span> 
                   		 <input id="text" type="text" placeholder="请输入关键词..." class="form-control" data-toggle="dropdown"/>
                   	<span style="padding-right: 60px"
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
					
					<span class="input-group-btn">
					<button class="btn btn-sm btn-primary" style="margin-right: 5px;" onclick="addUpdateDictItem('0')">新增</button>
					<button class="btn btn-sm btn-primary" onclick="delAll()">删除所有</button>
					</span>
				</div>
			</div>
		 	<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
					<!-- 
					<span>当前已选择10条记录:</span> <select
						class="table-group-action-input form-control input-inline input-small input-sm mlm">
						<option value="">选择可操作项...</option>
						<option value="Cancel">删除</option>
					</select>&nbsp;
					<button class="btn btn-sm btn-primary">
						<i class="fa fa-check"></i>&nbsp; 提交
					</button>
					-->
					
				</div>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th width="8%">序号</th>
					<th>中文名称</th>
					<th>英文名称</th>
					<th>字典项值</th>
					<th>排序</th>
					<th width="20%">操作</th>
				</tr>
			</thead>
			<tbody id="findallDictItem"></tbody>
		</table>
		<div id="dataNull" class="panel-body"
				 align="center">
		</div>
		<div id="page" style="text-align: center; margin-top: 20px;"></div>
	</div>
	<!--END CONTENT-->
</div>

<?} ?>
<!-- 
<iframe name="child" src="dictItem-add-updateBiao.html" id="ifr" style="HEIGHT: 0px; LEFT: 0px; POSITION: absolute;  WIDTH: 0px"></iframe>
 -->
<script>
 	var dictId = window.parent.getlay();
	var index = parent.layer.getFrameIndex(window.name); 
	var curr;
	var id;

	$(function() {
		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	function getaddupate() {
		return id;
	}
	function getDictId() {
		return dictId;
	}
	
	function addUpdateDictItem(lid) {
		id = lid;
		layer.open({
		 	type : 2,
		 	title : '字典项管理',
			area : [ '550px', '450px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["dictItem-add-updateBiao.html",'no'],
			
			yes: function(index,layer){
					var iframeWin = window.parent.window[window.name].window['layui-layer-iframe'+index];
	                 iframeWin.Page2();
  	        },
			cancel : function(index) {
				
			}
		});
	}
	function del(id) {
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "./deldictiem.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data.count==1){
						layer.msg('删除成功！');
					}else{
						layer.msg('有关联,不可删除！');
					}
					demo1();
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	
	//删除所有
	function delAll() {
			if (confirm("是否确认删除所有！！"))
			{
				$.ajax({
					type : "post",
					url : "./deldictiemAll.do",
					data : {
						"id" : dictId
					},
					dataType : "json",
					success : function(data) {
						if(data.count==1){
							layer.msg('删除成功！');
							
						}
						demo1();
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}
	}
	
	function demo1(curr) {
			$.ajax({
				type : "post",
				url : "./findallDictItemBiao.do",
				data :{
					page : curr || 1,
					"dictId" : dictId,
					queryParams : $("#queryParams").val(),
        			text : $("#text").val()
				},
				dataType : "json",
				success : function(res) {
					//此处仅仅是为了演示变化的内容
							//alert(""+res.pageSize);
							var str = "";
							if(res.listsize>0){
								$("#dataNull").html("");
							}else{
								$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
							}
							$("#findallDictItem").html("");
							for ( var i = 0; i < res.listsize; i++) {
							//alert("id :"+res.result[i].id+"nameZh :  "+res.result[i].nameZh+ "  nameEn:  "+ res.result[i].nameEn+"  sort:  "+res.result[i].sort+"  dict:  "+res.result[i].dictNameZh);
								str += "<tr>"
										+"<td>"+ (i + 1)+ "</td>"
										+"<td> <label>"+ res.result[i].nameZh + "</label></td>"
										+"<td><label >"+ res.result[i].nameEn + "</label></td>"
										+"<td><label >"+ res.result[i].value + "</label></td>"
										+"<td><label >"+ res.result[i].sort+ "</label></td>"
										+"<td>"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"del('"+ res.result[i].id+ "')\">删除</button>&nbsp;&nbsp;"
										+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"addUpdateDictItem('"+ res.result[i].id+ "')\">编辑</button>" 
										+ "</td></tr>";
							}
								sum=res.listsize;
								//alert(""+res.pageSize);
								//salert("str2 : "+str);
								$("#findallDictItem").append(str);
								laypage({
									cont : document.getElementById('page'), //容器。值支持id名、原生dom对象，jquery对象,
									pages : res.pageSize, //总页数
									skip : true, //是否开启跳页
									skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
									curr: curr || 1,
									last: res.pageSize,
									groups : 6,//连续显示分页数
									jump : function(obj, first) { //触发分页后的回调
										if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
											demo1(obj.curr);
							                 curr=obj.curr;
										}
									}
							});
				},
				error : function(data) {
					alert("请求失败");
				}
			});
			
		};

	//总数
	var sum;
	function getSum() {
		return sum+1;
	}
</script>